package p270jp.pxv.android.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.android.material.imageview.ShapeableImageView;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import p014ae.View$OnClickListenerC0159t4;
import p045be.View$OnClickListenerC1067e2;
import p045be.View$OnClickListenerC1095o;
import p062c4.ViewBindings;
import p064c6.Preconditions;
import p210hh.PixivAccountManager;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.UserProfileActivity;
import p270jp.pxv.android.commonObjects.model.PixivComment;
import p270jp.pxv.android.commonObjects.model.Stamp;
import p270jp.pxv.android.legacy.model.EmojiDaoManager;
import p270jp.pxv.android.legacy.model.PixivWork;
import p314lg.ViewCommentItemBinding;
import p325m0.MutabilityOwnership;
import p374nm.C5390e;
import p374nm.C5391f;
import p374nm.View$OnClickListenerC5389d;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p547uh.View$OnClickListenerC6437f8;
import p603wm.AbstractC6949c;
import p677zi.PixivImageLoader;

/* compiled from: CommentItemView.kt */
/* renamed from: jp.pxv.android.view.CommentItemView */
/* loaded from: classes2.dex */
public final class CommentItemView extends RelativeLayout implements AbstractC5475a {

    /* renamed from: d */
    public static final Pattern f19464d = Pattern.compile("\\(([a-z0-9]+)\\)");

    /* renamed from: a */
    public final ViewCommentItemBinding f19465a;

    /* renamed from: b */
    public final AbstractC6949c f19466b = Preconditions.m9802P(1, new C5390e(this, null, null));

    /* renamed from: c */
    public final AbstractC6949c f19467c = Preconditions.m9802P(1, new C5391f(this, null, null));

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public CommentItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        MutabilityOwnership.m3745m(context, "context");
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_comment_item, (ViewGroup) this, false);
        addView(inflate);
        int i = R.id.author_comment_mark;
        TextView textView = (TextView) ViewBindings.m9835b(inflate, R.id.author_comment_mark);
        if (textView != null) {
            i = R.id.comment_text_view;
            TextView textView2 = (TextView) ViewBindings.m9835b(inflate, R.id.comment_text_view);
            if (textView2 != null) {
                i = R.id.date_text_view;
                TextView textView3 = (TextView) ViewBindings.m9835b(inflate, R.id.date_text_view);
                if (textView3 != null) {
                    i = R.id.dot_text_front_of_remove_button;
                    TextView textView4 = (TextView) ViewBindings.m9835b(inflate, R.id.dot_text_front_of_remove_button);
                    if (textView4 != null) {
                        i = R.id.dot_text_front_of_reply_button;
                        TextView textView5 = (TextView) ViewBindings.m9835b(inflate, R.id.dot_text_front_of_reply_button);
                        if (textView5 != null) {
                            i = R.id.profile_image_view;
                            ImageView imageView = (ImageView) ViewBindings.m9835b(inflate, R.id.profile_image_view);
                            if (imageView != null) {
                                i = R.id.remove_button;
                                TextView textView6 = (TextView) ViewBindings.m9835b(inflate, R.id.remove_button);
                                if (textView6 != null) {
                                    i = R.id.reply_button;
                                    TextView textView7 = (TextView) ViewBindings.m9835b(inflate, R.id.reply_button);
                                    if (textView7 != null) {
                                        i = R.id.stamp_image;
                                        ShapeableImageView shapeableImageView = (ShapeableImageView) ViewBindings.m9835b(inflate, R.id.stamp_image);
                                        if (shapeableImageView != null) {
                                            i = R.id.user_name_text_view;
                                            TextView textView8 = (TextView) ViewBindings.m9835b(inflate, R.id.user_name_text_view);
                                            if (textView8 != null) {
                                                this.f19465a = new ViewCommentItemBinding((RelativeLayout) inflate, textView, textView2, textView3, textView4, textView5, imageView, textView6, textView7, shapeableImageView, textView8);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
    }

    private final EmojiDaoManager getEmojiDaoManager() {
        return (EmojiDaoManager) this.f19466b.getValue();
    }

    private final PixivImageLoader getPixivImageLoader() {
        return (PixivImageLoader) this.f19467c.getValue();
    }

    /* renamed from: a */
    public final void m4513a(long j) {
        Context context = getContext();
        Context context2 = getContext();
        MutabilityOwnership.m3746l(context2, "context");
        context.startActivity(UserProfileActivity.m4690e1(context2, j));
    }

    /* renamed from: b */
    public final void m4512b(PixivComment pixivComment, PixivWork pixivWork, boolean z) {
        MutabilityOwnership.m3745m(pixivComment, "comment");
        MutabilityOwnership.m3745m(pixivWork, "work");
        long id = pixivComment.getUser().getId();
        boolean z2 = id == PixivAccountManager.m5511e().f16499e;
        if (id == pixivWork.user.f19078id) {
            this.f19465a.f21573b.setVisibility(0);
        } else {
            this.f19465a.f21573b.setVisibility(8);
        }
        this.f19465a.f21578g.setOnClickListener(new View$OnClickListenerC5389d(this, id, 0));
        this.f19465a.f21582k.setOnClickListener(new View$OnClickListenerC6437f8(this, id, 1));
        PixivImageLoader pixivImageLoader = getPixivImageLoader();
        Context context = getContext();
        MutabilityOwnership.m3746l(context, "context");
        String medium = pixivComment.getUser().getProfileImageUrls().getMedium();
        ImageView imageView = this.f19465a.f21578g;
        MutabilityOwnership.m3746l(imageView, "binding.profileImageView");
        pixivImageLoader.m60f(context, medium, imageView);
        if (z2) {
            this.f19465a.f21580i.setVisibility(8);
            this.f19465a.f21577f.setVisibility(8);
        } else {
            this.f19465a.f21580i.setVisibility(0);
            this.f19465a.f21577f.setVisibility(0);
        }
        boolean z3 = pixivWork.user.f19078id == PixivAccountManager.m5511e().f16499e;
        if (z2 || z3) {
            this.f19465a.f21579h.setVisibility(0);
            this.f19465a.f21576e.setVisibility(0);
        } else {
            this.f19465a.f21579h.setVisibility(8);
            this.f19465a.f21576e.setVisibility(8);
        }
        this.f19465a.f21582k.setText(pixivComment.getUser().getName());
        this.f19465a.f21575d.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).format(pixivComment.getDate()));
        if (pixivComment.getStamp() != null) {
            this.f19465a.f21574c.setVisibility(8);
            this.f19465a.f21581j.setVisibility(0);
            PixivImageLoader pixivImageLoader2 = getPixivImageLoader();
            Context context2 = getContext();
            MutabilityOwnership.m3746l(context2, "context");
            ShapeableImageView shapeableImageView = this.f19465a.f21581j;
            MutabilityOwnership.m3746l(shapeableImageView, "binding.stampImage");
            Stamp stamp = pixivComment.getStamp();
            if (stamp != null) {
                pixivImageLoader2.m52n(context2, shapeableImageView, stamp);
            } else {
                throw new IllegalStateException("Required value was null.".toString());
            }
        } else {
            TextView textView = this.f19465a.f21574c;
            String comment = pixivComment.getComment();
            float textSize = this.f19465a.f21574c.getTextSize() * ((float) 2);
            Matcher matcher = f19464d.matcher(comment);
            SpannableString spannableString = new SpannableString(comment);
            while (matcher.find()) {
                Bitmap emoji = getEmojiDaoManager().getEmoji(matcher.group(1));
                if (emoji != null) {
                    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), emoji);
                    int i = (int) textSize;
                    bitmapDrawable.setBounds(0, 0, i, i);
                    spannableString.setSpan(new ImageSpan(bitmapDrawable, 0), matcher.start(), matcher.end(), 17);
                }
            }
            textView.setText(spannableString);
            this.f19465a.f21574c.setVisibility(0);
            this.f19465a.f21581j.setVisibility(8);
        }
        if (z) {
            this.f19465a.f21580i.setOnClickListener(new View$OnClickListenerC1067e2(this, pixivWork, pixivComment, 1));
        } else {
            this.f19465a.f21580i.setOnClickListener(new View$OnClickListenerC1095o(pixivWork, pixivComment, 7));
        }
        this.f19465a.f21579h.setOnClickListener(new View$OnClickListenerC0159t4(pixivComment, pixivWork, 7));
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }
}
